package com.shxzz.easy12306.framework.starter.user.config;

import com.shxzz.easy12306.framework.starter.base.constant.FilterOrderConstant;
import com.shxzz.easy12306.framework.starter.user.core.UserTransmitFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * 用户业务自动装配
 * @author shxzz
 * @create 2024-02-24-19:12
 */
@ConditionalOnClass(jakarta.servlet.Filter.class)   // 兼容网关
public class UserBizAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean
    public FilterRegistrationBean<UserTransmitFilter> userTransmitFilter() {
        FilterRegistrationBean<UserTransmitFilter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(new UserTransmitFilter());
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(FilterOrderConstant.USER_TRANSMIT_FILTER);
        return filterRegistrationBean;
    }
}
